package com.xingren.wms.api;

import com.xingren.common.data.JsonResult;
import com.xingren.spring.exception.XrExceptionHandler;
import com.xingren.v.logging.annotations.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@ControllerAdvice
public class ApiExceptionHandler {

    @Autowired
    private XrExceptionHandler exceptionHandler;

    /**
     * 捕获所有异常
     */
    @ExceptionHandler(Throwable.class)
    @ResponseBody
    public JsonResult handleAllException(HttpServletRequest request,
                                         HttpServletResponse response,
                                         Throwable error) {

        return exceptionHandler.handleException(request, response, error);
    }

}

